package example.service.impl;

import example.dao.ShipInfoDao;
import example.pojo.Pager;
import example.pojo.ShipInfo;
import example.service.ShipInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;



@Service("shipInfoService")
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
public class ShipInfoServiceImpl implements ShipInfoService {

	@Autowired(required = false)
	ShipInfoDao shipInfoDao;

	@Override
	public List<ShipInfo> findShipInfo(ShipInfo shipInfo, Pager pager) {
		// 创建对象params
		Map<String, Object> params = new HashMap<String, Object>();
		// 将封装有查询条件的ShipInfo对象放入params
		params.put("shipInfo", shipInfo);
		// 根据条件计算商品总数
		int recordCount = shipInfoDao.count(params);
		// 给pager对象设置rowCount属性值(记录总数)
		pager.setRowCount(recordCount);
		if (recordCount > 0) {
			// 将page对象放入params
			params.put("pager", pager);
		}
		// 分页获取商品信息
		return shipInfoDao.selectByPage(params);
	}

	@Override
	public Integer count(Map<String, Object> params) {
		return shipInfoDao.count(params);
	}


	@Override
	public void addShipInfo(ShipInfo pi) {
		shipInfoDao.save(pi);
	}

	@Override
	public void modifyShipInfo(ShipInfo pi) {
		shipInfoDao.edit(pi);
	}

	@Override
	public void modifyStatus(String ids, int flag) {
		shipInfoDao.updateState(ids, flag);
	}

	@Override
	public List<ShipInfo> getOnSaleShip() {
		return shipInfoDao.getOnSaleShip();
	}

	@Override
	public ShipInfo getShipInfoById(int id) {
		return shipInfoDao.getShipInfoById(id);
	}
}
